﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Phone.Controls;

namespace WhallaToolkit.FeedbackControl
{
    public sealed class FeedbackControl
    {
        /// <summary>
        /// Represents where created feedback should be sent.
        /// </summary>
        private string emailAddress = string.Empty;
        private string applicationName = string.Empty;

        internal FeedbackControl(string email, string applicationName)
        {
            this.emailAddress = email;
            this.applicationName = applicationName;
        }

        #region Public Methods
        /// <summary>
        /// Shows new page where user can type his feedback for app. 
        /// </summary>
        /// <param name="emailAddress">Email address which feedback will be sent.</param>
        public static void Show(string emailAddress, string applicationName)
        {
            FeedbackControl control = new FeedbackControl(emailAddress, applicationName);
            control.NavigateToFeedbackPage();
        }
        #endregion

        #region Private Methods

        internal void NavigateToFeedbackPage()
        {
            var rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;

            if (rootFrame == null)
            {
                throw new InvalidOperationException();
            }

            rootFrame.Navigate(new Uri(string.Format("/WhallaToolkit;component/FeedbackControl/FeedbackPage.xaml?emailAddress={0}&appName={1}",emailAddress,applicationName), UriKind.Relative));
        }
        #endregion
    }
}
